<script setup lang="ts">

import {HospitalLevelAndRegionArr, HospitalLevelAndRegionResponseData} from "@/api/home/type.ts";
import {reqHospitalLevelAndRegion} from "@/api/home";
import {onMounted, ref} from "vue";
let regionArr = ref<HospitalLevelAndRegionArr>([]);
let activeFlag = ref<string>('');
onMounted(()=>{
  getRegion();
})
const getRegion = async ()=>{
  let result: HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('Beijing');
  if(result.code==200){
    regionArr.value = result.data;
  }
}
const changeRegion=(region:string)=>{
  activeFlag.value = region;
  //给父组件传递区域的参数
  $emit('getRegion',region);
}
let $emit = defineEmits(['getRegion'])
</script>
<script lang="ts">
export default {
  name:"Region"
}
</script>
<template>
  <div class="region">
    <div class="content">
      <div class="left">地区：</div>
      <ul>
        <li :class="{active:activeFlag==''}" @click="changeRegion('')">全部</li>
        <li v-for="item in regionArr" :key="item.value" @click="changeRegion(item.value)" :class="{active:activeFlag==item.value}">{{item.name}}</li>

      </ul>
    </div>
  </div>
</template>

<style scoped lang="scss">
  .region{
    color:#7f7f7f;
    margin-top: 10px;
    .content{
      display: flex;
      .left{
        margin-right: 10px;
        width: 53px;
      }
      ul{
        display: flex;
        flex-wrap: wrap;
        li{
          margin-right: 10px;
          margin-bottom: 10px;
          &.active{
            color:#55a6fe;
          }
        }
        li:hover{
          color:#55a6fe;
          cursor:pointer;
        }
      }
    }
  }

</style>
